<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.List" %>
<%@ page import="cn.acmoj.oj.bean.Ranklist" %>
<%@ page import="com.sun.istack.internal.NotNull" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>${applicationScope.ojName}</title>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/amazeui.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/amazeui.flat.min.css"/>
    <style>
        .main {
            width: 60%;
            margin: 0 auto;
        }

        .title {
            background: #FFF;
            border-bottom: solid 1px #CCCCCC;
            padding: 10px;
            margin-bottom: 30px;
        }

        .title h2 {
            font-size: 2em;
            width: 100%;
            text-align: center;
        }

        .rank_main {
            margin: 10px;
            font-size: 14px;
        }

        .rank_main table {
            text-align: center;
        }

        table {
            margin: 0 auto;
            text-align: center;
        }

        table * {
            text-align: center;
            margin: 0;
        }

        .rank,
        .num,
        .time {
            width: 50px;
        }

        .uid {
            width: 150px;
        }

        .name {
            width: 170px;
        }

        .problem {
            width: 50px;
        }

        .my_rank {
            font-size: 16px;
            font-weight: bold;
            margin-bottom: 10px;
        }
    </style>
</head>

<body>

<jsp:include page="/contest/heard.html" flush="true"/>

<div class="title">
    <div class="main">
        <h2>${requestScope.contest.title} </h2>
        <p>${requestScope.contest.content}</p>
    </div>
</div>

<div class="rank_main">
    <div class="main">
        <a href="#">导出Excel</a>
        <div class="my_rank">
            我的排名：
            <c:choose>
                <c:when test="${requestScope.myRank == 0}">
                    --
                </c:when>
                <c:otherwise>
                    ${requestScope.myRank}
                </c:otherwise>
            </c:choose>
        </div>
    </div>
    <table class="am-table am-table-bordered am-table-hover" style="width: auto;min-width: 60%;">
        <thead>
        <tr>
            <th>排名</th>
            <th>学号</th>
            <th>姓名</th>
            <th>题数</th>
            <th>时间</th>
            <%
                for (int i = 0; i < (int) request.getAttribute("num"); i++) {
            %>
            <th>
                <%=(char) (i + 'A')%>
            </th>
            <%
                }
            %>
        </tr>
        </thead>
        <tbody>
        <%
            int rank = 0;
            List<Ranklist> list = (List<Ranklist>) request.getAttribute("list");
            for (Ranklist ranklist : list) {
                if (ranklist.getNick().charAt(0) != '*') {
                    rank++;
                }
        %>
        <tr>
            <td class="rank">
                <%
                    if (ranklist.getNick().charAt(0) != '*' && ranklist.getSolved() > 0) {
                        out.print(rank);
                    } else {
                        out.print("*");
                    }
                %>
            </td>
            <td class="uid">
                <%=ranklist.getUser_id()%>
            </td>
            <td class="name">
                <%=ranklist.getNick()%>
            </td>
            <td class="num">
                <%=ranklist.getSolved()%>
            </td>
            <td class="time">
                <%
                    long s, m, h = ranklist.getTime();
                    h /= 1000;
                    s = h % 60;
                    h /= 60;
                    m = h % 60;
                    h /= 60;
                    out.print(h + ":");
                    if (m < 10) {
                        out.print(0);
                    }
                    out.print(m + ":");
                    if (s < 10) {
                        out.print(0);
                    }
                    out.print(s);
                %>
            </td>
            <!--各个题目情况-->
            <%
                for (int j = 0; j < (int) request.getAttribute("num"); j++) {
            %>
            <%
                if (ranklist.getP_ac_sec()[j] > 0) {
            %>
            <td class="problem <%=(char)(j+'A')%>  am-success">
                    <%
            }else if (ranklist.getP_ac_sec()[j] < 0){
                %>
            <td class="problem <%=(char)(j+'A')%>  am-primary">
                    <%
            }else if (ranklist.getP_wa_num()[j]>0){
                %>
            <td class="problem <%=(char)(j+'A')%>  am-danger">
                    <%
            }else if (ranklist.getP_wa_num()[j]==0){
                %>
            <td class="problem <%=(char)(j+'A')%>">
                    <%
            }else{
                %>
            <td class="problem <%=(char)(j+'A')%> active">
                <%
                    }
                    if (ranklist.getP_ac_sec()[j] != 0) {
                        long is, im, ih = Math.abs(ranklist.getP_ac_sec()[j]) / 1000;
                        is = ih % 60;
                        ih /= 60;
                        im = ih % 60;
                        ih /= 60;
                        out.print(ih + ":");
                        if (im < 10) {
                            out.print(0);
                        }
                        out.print(im + ":");
                        if (is < 10) {
                            out.print(0);
                        }
                        out.print(is);
                    }
                    if (ranklist.getP_wa_num()[j] > 0) {
                        if (ranklist.getP_ac_sec()[j] != 0) {
                            out.print("<br/>");
                        } else {
                            out.print("&nbsp;");
                        }
                        out.print("(-" + ranklist.getP_wa_num()[j] + ")");
                    }
                %>
            </td>
            <%
                }
            %>
            <!--End 各个题目情况-->
        </tr>
        <%
            }
        %>

        </tbody>
    </table>
</div>

<jsp:include page="/foot.html" flush="true"/>

<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/amazeui.min.js"></script>
<script>
    $(function () {
        $('.ranklist').addClass('am-active');
        $('.rank,.uid,.name,.num,.time,.problem').css({
            'padding': '0 10px',
            'vertical-align': 'middle'
        });
        $('.rank').css({
            'padding': '10px'
        });
    })
</script>
</body>

</html>
<!--http://contests.acmicpc.info/contests.json-->
<!--数据来源：http://contests.acmicpc.info/contests.json-->